﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;

public class GazePoint : MonoBehaviour
{
    public Image progress;
    public Image point;
    public Text percent;
    SetScaleByDistance setScale;

    // Use this for initialization
    void Start()
    {
        setScale = GetComponent<SetScaleByDistance>();
        SetGazePointActive(false);
    }

    private void Update()
    {
        SetPosition(VRManager.manager.trackedObjectManager.eye.position + VRManager.manager.trackedObjectManager.eye.forward * 5);
    }
    public void SetProgress(float p)
    {
        //if (!progress.gameObject.active)
        //{
        //    progress.gameObject.SetActive(true);
        //}
        p = Mathf.Clamp01(p);
        percent.text = Mathf.CeilToInt(p * 100) + "%";
        progress.fillAmount = p;
        if (p >= 1)
        {
            SetGazePointActive(false);
            // completed.gameObject.SetActive(true);
        }
    }
    public void SetGazePointActive(bool b)
    {
        progress.gameObject.SetActive(b);
        SetProgress(0);
    }

    public void LightPoint(bool b)
    {
        //Color c = progress.color;
        //c.a = b ? 1 : 0.5f;
        //progress.color = c;
        //c = percent.color;
        //c.a = b ? 1 : 0.5f;
        //percent.color = c;
        //c = point.color;
        //c.a = b ? 1 : 0.5f;
        //point.color = c;
    }
    protected void SetPosition(Vector3 point)
    {
        transform.position = point;
        transform.forward = (point - VRManager.manager.trackedObjectManager.eye.position).normalized;
        setScale.SetScale();
    }

}
